﻿namespace EFS.RC.CC.Deployment.Tables.Tools
{
	public static class CustomerEndPoints
	{
		/// Returns an object from a data row
		public static EFS.RC.CC.Deployment.Views.EndPoints.CustomerDetails FromTableRow_Details(System.Data.DataRow row)
		{
			// check
			EFS.Common.Verify.Reference(row, "row");

			// create new
			EFS.RC.CC.Deployment.Views.EndPoints.CustomerDetails dataObj = new EFS.RC.CC.Deployment.Views.EndPoints.CustomerDetails();

			// ID
			dataObj.ID = EFS.DB.DataRow.Int32(row, "ID");

			// TEL
			dataObj.URI = EFS.DB.DataRow.String(row, "TEL");

			// Skill
			dataObj.SkillName = EFS.DB.DataRow.String(row, "SkillName");

			// SKILL_ID
			dataObj.SkillID = EFS.DB.DataRow.Int32(row, "SKILL_ID");

			// OfficeSIP
			dataObj.OfficeEndPointSIP = EFS.DB.DataRow.String(row, "OfficeSIP");

			// OFFICE_ENDPOINT_ID
			dataObj.OfficeEndPointID = EFS.DB.DataRow.Int32(row, "OFFICE_ENDPOINT_ID");

			// ok
			return dataObj;
		}

		/// GetAll
		public static EFS.RC.CC.Deployment.Entities.EndPoints.Customer[] GetAll()
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.Deployment.Entities.EndPoints.Customer>(
					"[dbo].[CustomerEndPoints_GetAll]", 
					null,
					EFS.RC.CC.Deployment.Tables.DataRow.EndPoints.Customer.Load);
			}
		}

		//GetAllDetails
		public static EFS.RC.CC.Deployment.Views.EndPoints.CustomerDetails[] GetAllDetails()
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.Deployment.Views.EndPoints.CustomerDetails>(
					"[dbo].[CustomerEndPoints_GetAllDetails]",
					null,
					FromTableRow_Details);
			}
		}

		/// GetByID
		public static EFS.RC.CC.Deployment.Entities.EndPoints.Customer GetByID(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteRowReaderQuery<EFS.RC.CC.Deployment.Entities.EndPoints.Customer>(
					"[dbo].[CustomerEndPoints_GetByID]",
					new EFS.DB.Parameters.Array("id", id),
					EFS.RC.CC.Deployment.Tables.DataRow.EndPoints.Customer.Load);
			}
		}

		/// GetByTel
		public static EFS.RC.CC.Deployment.Entities.EndPoints.Customer GetByTel(System.String tel)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteRowReaderQuery<EFS.RC.CC.Deployment.Entities.EndPoints.Customer>(
					"[dbo].[CustomerEndPoints_GetByTel]",
					new EFS.DB.Parameters.Array("tel", tel),
					EFS.RC.CC.Deployment.Tables.DataRow.EndPoints.Customer.Load);
			}
		}

		/// Create
		public static System.Int32? Create(
			System.String tel,
			System.Int32 skillID,
			System.Int32 officeEndpointID)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// make params
				EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
					new System.String[] { "tel", "skill_id", "office_endpoint_id", "id" },
					new System.Object[] { tel, skillID, officeEndpointID, default(System.Int32) },
					new System.Boolean[] { false, false, false, true });

				// ok
				connection.DoExecuteNonQuery("[dbo].[CustomerEndPoints_Create]", parametersArray);

				// get id vaoue
				return parametersArray.GetOutPrameterValue<System.Int32?>("id");
			}
		}

		/// Update
		public static void Update(
			System.Int32 id,
			System.String tel,
			System.Int32 skillID,
			System.Int32 officeEndpointID)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				connection.DoExecuteNonQuery(
					"[dbo].[CustomerEndPoints_Update]",
					new EFS.DB.Parameters.Array(
							new System.String[] { "id", "tel", "skill_id", "office_endpoint_id" },
							new System.Object[] { id, tel, skillID, officeEndpointID }));
			}
		}

		/// Delete
		public static void Delete(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				connection.DoExecuteNonQuery("[dbo].[CustomerEndPoints_Delete]", new EFS.DB.Parameters.Array("id", id));
			}
		}
	}

}